import defaultData from "./data";
import Props from "../base/Props";
import { WeaSelect, WeaBrowser, WeaLocaleProvider } from 'ecCom';
import { Row } from 'antd';
import { selectType } from '../../../../../constants/form';

const { CURRENT, APPOINT, EMPTY } = selectType;
const getLabel = WeaLocaleProvider.getLabel;

export default class MultiBrowserHrmProps extends Props {

  refsDefaultValue = () => {
    return { defaultValue: '' }
  }

  renderDefaultValue() {
    const { data } = this.props;
    const { type: t, defaultValue: dv } = defaultData;
    const { type = t, defaultValue = dv } = data;
    const options = [
      {
        showname: '',
        key: EMPTY
      },
      {
        showname: getLabel(384035, '当前人员'),
        key: CURRENT,
      },
      {
        showname: getLabel(514999, '指定人员'),
        key: APPOINT
      }
    ];
    
    return (
      <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@1whzcq`}>
        <label>{getLabel(502451, '默认值')}</label>
        <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@anldg6`}
          style={{ minWidth: '100%' }}
          value={type}
          options={options}
          onChange={this.handlePropChange('type:(refs=refsDefaultValue)')}
        />
        {
          type === APPOINT && 
          <div className='mt20'>
            <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@v6xc8o`}>
              <label>{getLabel(502424, '请选择人员')}</label>
              <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@nfwfol`}
                title={getLabel(516509, '多人力资源')}
                type={1}
                textDecoration={true}
                replaceDatas={defaultValue}
                inputStyle={{ width: '100%' }}
                isSingle={false}
                onChange={(ids, names) => {
                  if (ids) {
                    const idsArr = ids.split(',');
                    const namesArr = names.split(',');
                    const finalArr = [];

                    idsArr.forEach((id, index) => {
                      finalArr.push({
                        id,
                        name: namesArr[index]
                      })
                    })
                    this.handlePropChange('defaultValue')(finalArr)
                  } else {
                    this.handlePropChange('defaultValue')('');
                  }
                }}
              />
            </Row>
          </div>
        }
      </Row>
    );
  }

  renderTipContent() {
    return (
      <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@vytclo`}>
        <label className="browserHrm-tip">
          <span>{getLabel(526737,'当前插件在填报时只有OA用户才会显示')}</span>
        </label>
      </Row>
    );
  }
}

MultiBrowserHrmProps.defaultProps = {
  data: defaultData
};